package org.example.springaop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class AspectDemo {

    @Pointcut("execution(* org.example.springaop.controller.*.*(..))")
    public void pt() {}

    @Before("pt()")
    public void before() {
        log.info("执行AspectDemo.before方法...");
    }

    @After("pt()")
    public void after() {
        log.info("执行AspectDemo.after方法...");
    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("执行AspectDemo.around方法...");
        Object result =  joinPoint.proceed();
        log.info("执行AspectDemo.around方法...");
        return result;
    }

    @AfterThrowing("execution(* org.example.springaop.controller.*.*(..))")
    public void afterThrowing() {
        log.info("执行AspectDemo.afterThrowing方法...");
    }

    @AfterThrowing("execution(* org.example.springaop.controller.*.*(..))")
    public void afterReturning() {
        log.info("执行AspectDemo.afterReturning方法...");
    }
}
